package com.gulimall.order.web;

import com.gulimall.common.constrant.OrderConstant;
import com.gulimall.order.entity.OrderEntity;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.UUID;

/**
 * @author kkk
 * @date 2022/8/3
 */
@Controller
public class IndexController {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/waitPay.html")
    public String waitPage(String page) {
        return "waitPay";
    }

    @ResponseBody
    @GetMapping("/test/createOrder")
    public void createOrder() {
        OrderEntity orderEntity = new OrderEntity();
        orderEntity.setOrderSn(UUID.randomUUID().toString());
        rabbitTemplate.convertAndSend(OrderConstant.ORDER_EVENT_EXCHANGE, OrderConstant.CREATE_ORDER_KEY, orderEntity);

        System.out.println("创建消息成功");
    }

}
